home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / ROBOTS3.ZIP / robots / sound.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-12  |  761 b   |  29 lines

  1. #include <conio.h>
  2. #include <dos.h>
  3.  
  4. #include "Timer.h"
  5.  
  6. #define SOUNDER 0x61
  7. /* SOUNDER bit values */
  8. #define MAKE_NOISE 0x02
  9. #define USE_TIMER2 0x01
  10.  
  11. static void Sleep(unsigned Time) { /* Use BIOS's 18.2 Hz clock */
  12.    union REGS R;
  13.    R.h.ah = 0; int86(0x1a, &R, &R); Time += R.x.dx;
  14.    do {
  15.       R.h.ah = 0; int86(0x1a, &R, &R);
  16.    } while (R.x.dx < Time);
  17. }
  18.  
  19. void Sound(unsigned Pitch, unsigned Duration) {
  20.    int Delay;
  21.    if (Pitch <= 10) { Sleep(Duration); return; }
  22.    Delay = (int)(FREQ/Pitch);
  23.    outp(SOUNDER, inp(SOUNDER) | (MAKE_NOISE | USE_TIMER2));
  24.    outp(T_CONTROL, CHANNEL2 | LSB_MSB | MODE3 | BINARY);
  25.    outp(TIMER2, Delay&0xff); outp(TIMER2, Delay >> 8);
  26.    Sleep(Duration);
  27.    outp(SOUNDER, inp(SOUNDER) & ~(MAKE_NOISE | USE_TIMER2));
  28. }
  29.